<!doctype html>
<html lang="<?php echo $cms['config']['lang']; ?>">
<head>
<meta charset="utf-8">
<?php
if ( is_admin() ) {
    echo "<title>".__('Admin')."</title>";
} elseif ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
           empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
    echo "<title>".__('Install')."</title>";
} else {
    echo "<title>".__('Auth')."</title>";
} ?>
<link rel="icon" href="<?php echo $cms['base_url']; ?>img/favicon.png">
<link rel="stylesheet" type="text/css" href="<?php echo $cms['base_url']; ?>css/select2.min.css">
<script src="<?php echo $cms['base_url']; ?>js/jquery-3.5.1.min.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/jquery.cookie.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/jquery.form.min.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/jquery.searcher.min.js"></script>

<link rel=stylesheet href="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/lib/codemirror.css">
<link rel=stylesheet href="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/hint/show-hint.css">
<link rel=stylesheet href="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/dialog/dialog.css">
<?php
$styles = array();
foreach( glob( $cms['cms_dir'].'/css/admin.*.css' ) as $file ) {
    preg_match( '/.*(\/admin\.(.*)\.(.*)\.css)/', $file, $m );
    echo "<link rel=stylesheet href='{$cms['base_url']}css{$m[1]}'>\n";
    array_push($styles,array($m[2],$m[3]));
}
echo "<script>\nadmin_styles = ".json_encode( $styles ).";\n";

if ( !empty( $cms['config']['locale'] ) ) {
    $lang = json_encode($cms["lang"]);
    $tr   = json_encode($cms["tr"]);
    echo "cms = {};
cms.locale = '{$cms['config']['locale']}';
cms.lang = {$lang};
cms.tr = {$tr};
</script>\n";
}
?>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/lib/codemirror.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/hint/show-hint.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/hint/xml-hint.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/hint/html-hint.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/selection/active-line.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/search/search.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/search/searchcursor.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/search/jump-to-line.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/addon/dialog/dialog.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/mode/xml/xml.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/mode/javascript/javascript.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/mode/css/css.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.53.2/mode/htmlmixed/htmlmixed.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/pages.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/menu.js"></script>
<script src='<?php echo $cms['base_url']; ?>js/select2.min.js' type='text/javascript'></script>
<script src='<?php echo $cms['base_url']; ?>lang/select2/<?php echo $cms['config']['lang']; ?>.js' type='text/javascript'></script>
<script src="<?php echo $cms['base_url']; ?>js/admin.js"></script>
<?php cms_do_stage('admin_header'); ?>
</head>


<?php if (is_admin()): ?>

<body class="logged">

    <header>
        <div class="headscroll">
        <div class="logo"><p class="namecms">Coffee CMS</p></div>
        <a href="/" class=open-front-page data-front target=_blank><?php echo __('Home'); ?></a>
        <a href="#" class=recreate-cache data-cache><?php echo __('Update Cache'); ?></a>
        <a href="#" class=theme-switcher data-theme><?php echo __('Theme'); ?></a>
        <a href="#" class=logout data-logout><?php echo __('Logout'); ?></a>
        </div>
    </header>

  <aside>
   <div class="adminmenuwrap">
     <div class="height-corrector">
<?php
foreach( $cms['admin_sections'] as $section_name => $section ) {
    if ( !isset($section['hide']) || isset($section['hide']) && !$section['hide'] ) {
        echo '<div class="adminmenubox">';
        echo "<h1>{$cms['admin_sections'][$section_name]['title']}</h1>";
        # Пункты секции
        if ( !empty( $cms['admin_sections'][$section_name]['items'] ) )
        foreach( $cms['admin_sections'][$section_name]['items'] as $page_name => $page ) {
            if ( !isset($page['hide']) || isset($page['hide']) && !$page['hide'] ) {
                $title = __($page['title'],$page['module']);
                if ( !empty($page['class']) ) {
                    $class = " class='{$page['class']}'";
                } else {
                    $class = "";
                }
                echo "<a href=# data-am-page='{$page_name}'{$class}>{$title}</a>";
            }
        }
        echo '</div>';
    }
}
?>
      </div>
    </div>
  </aside>


  <main>
<?php

    foreach( $cms['admin_pages'] as $name => $page ) {
        echo "<div class='hidden' data-settings={$name}>{$page}</div>";
    }
    
?>
  </main>

  <footer>
  <a href="http://coffee-cms.com/instrukcii/" class="version cms" target=_blank>ver. 20.08</a>
  </footer>


<?php else: ?>

<body class="login">
  
    <header class="logintoppanel headscroll">
        <a href="#" class=theme-switcher data-theme><?php echo __('Theme'); ?></a>
    </header>

    <div class="authorization-box">
        <div class="authorization-logo"></div>
        <?php if ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
                   empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
            echo "<div class='setup-auth'>".__('Setup Login and Password')."</div>";
        } ?>
        <div class="authorization">
            <div class="authorization-input-log">
                <input placeholder="<?php echo __('Login or Email'); ?>" name="login" type="text" class="authorization-settingx-log">
            </div>
            <div class="authorization-input-pass">
                <input placeholder="<?php echo __('Password'); ?>" name="password" type="password" class="authorization-settingx-pass">
                <div title="<?php echo __('Enter'); ?>" class="button-adminix-avtor" type="submit" data-login-btn></div>
            </div>
        </div>
    </div>
    
<?php endif; ?>
    
<div class="log-info-box">
    <!-- div for messages -->
</div>

</body>
</html>
